<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META name="GENERATOR" content="IBM WebSphere Homepage Builder V4.0.0 for Linux">
<TITLE></TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">
<PRE>#include        &quot;unp.h&quot;

int
main(int argc, char **argv)
{
        int                                     sockfd, n;
        char                            recvline[MAXLINE + 1];
        struct sockaddr_in      servaddr;

        if (argc != 2)
                err_quit(&quot;usage: a.out &lt;IPaddress&gt;&quot;);

        if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0)
                err_sys(&quot;socket error&quot;);

        bzero(&amp;servaddr, sizeof(servaddr));
        servaddr.sin_family = AF_INET;
        servaddr.sin_port   = htons(13);        /* daytime server */
        if (inet_pton(AF_INET, argv[1], &amp;servaddr.sin_addr) &lt;= 0)
                err_quit(&quot;inet_pton error for %s&quot;, argv[1]);

        if (connect(sockfd, (SA *) &amp;servaddr, sizeof(servaddr)) &lt; 0)
                err_sys(&quot;connect error&quot;);

        while ( (n = read(sockfd, recvline, MAXLINE)) &gt; 0) {
                recvline[n] = 0;        /* null terminate */
                if (fputs(recvline, stdout) == EOF)
                        err_sys(&quot;fputs error&quot;);
        }
        if (n &lt; 0)
                err_sys(&quot;read error&quot;);

        exit(0);
}</PRE>
<P><BR></P>
<PRE>#include        &quot;unp.h&quot;
#include        &lt;time.h&gt;

int
main(int argc, char **argv)
{
        int                                     listenfd, connfd;
        struct sockaddr_in      servaddr;
        char                            buff[MAXLINE];
        time_t                          ticks;

        listenfd = Socket(AF_INET, SOCK_STREAM, 0);

        bzero(&amp;servaddr, sizeof(servaddr));
        servaddr.sin_family      = AF_INET;
        servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
        servaddr.sin_port        = htons(13);   /* daytime server */

        Bind(listenfd, (SA *) &amp;servaddr, sizeof(servaddr));

        Listen(listenfd, LISTENQ);

        for ( ; ; ) {
                connfd = Accept(listenfd, (SA *) NULL, NULL);

        ticks = time(NULL);
        snprintf(buff, sizeof(buff), &quot;%.24s\r\n&quot;, ctime(&amp;ticks));
        Write(connfd, buff, strlen(buff));

                Close(connfd);
        }
}</PRE>
</BODY>
</HTML>
